package com.lcf.system.controller;

import com.lcf.framework.annotation.PermissionCheck;
import com.lcf.framework.vo.PageVO;
import com.lcf.system.dto.role.SysRoleDTO;
import com.lcf.system.query.role.SysRolePageQuery;
import com.lcf.system.service.SysRoleService;
import com.lcf.system.vo.role.SysRoleVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.lcf.framework.enums.PermissionEnum.*;

/**
 * 角色(SysRole)表控制层
 *
 * @author lcf
 * @since 2025-02-25 12:28:29
 */
@Tag(name = "角色")
@RestController
@RequestMapping("sysRole")
public class SysRoleController {
    @Resource
    private SysRoleService sysRoleService;

    /**
     * 新增角色
     */
    @Operation(summary = "新增角色")
    @PermissionCheck(SYS_ROLE_ADD)
    @PostMapping
    public void add(@RequestBody @Validated SysRoleDTO dto) {
        sysRoleService.add(dto);
    }

    /**
     * 编辑角色
     */
    @Operation(summary = "编辑角色")
    @PermissionCheck(SYS_ROLE_EDIT)
    @PatchMapping("{id}")
    public void update(@PathVariable @Schema(description = "角色ID") long id,
                       @RequestBody @Validated SysRoleDTO dto) {
        sysRoleService.update(id, dto);
    }

    /**
     * 删除角色
     */
    @Operation(summary = "删除角色")
    @PermissionCheck(SYS_ROLE_DEL)
    @DeleteMapping("{id}")
    public void delete(@PathVariable @Schema(description = "角色ID") long id) {
        sysRoleService.delete(id);
    }

    /**
     * 获取角色分页列表
     */
    @Operation(summary = "获取角色分页列表")
    @PermissionCheck(SYS_ROLE_PAGE)
    @GetMapping("page")
    public PageVO<SysRoleVO> getPage(SysRolePageQuery query) {
        return sysRoleService.getPage(query);
    }

    /**
     * 获取全部角色列表
     */
    @Operation(summary = "获取全部角色列表")
    @PermissionCheck(SYS_ROLE_LIST)
    @GetMapping("list")
    public List<SysRoleVO> getAll() {
        return sysRoleService.getAll();
    }

    /**
     * 获取角色详情
     */
    @Operation(summary = "获取角色详情")
    @PermissionCheck(SYS_ROLE_DETAIL)
    @GetMapping("{id}")
    public SysRoleVO getDetail(@PathVariable @Schema(description = "角色ID") long id) {
        return sysRoleService.getDetail(id);
    }
}

